var myExtension = {
    oldURL: null,
 
    init: function() {
		//alert("calling init2");
        gBrowser.addProgressListener(this);
    },
 
    uninit: function() {
		//alert("it is unloading..");
        gBrowser.removeProgressListener(this);
    },
    
    submitHandler : function(e) {
    	alert(e.target);
      //  encodeScript(e.target);
    },
 
    processNewURL: function(aURI) {
        if (aURI.spec == this.oldURL) return;
 
        // now we know the url is new...
        //alert(aURI.spec);
		//encodeScript();
        this.oldURL = aURI.spec;
    },
 
    // nsIWebProgressListener
    QueryInterface: XPCOMUtils.generateQI(["nsIWebProgressListener",
                                           "nsISupportsWeakReference"]),
 
    onLocationChange: function(aProgress, aRequest, aURI) {
        this.processNewURL(aURI);
    },
 
    onStateChange: function() {},
    onProgressChange: function() {},
    onStatusChange: function() {},
    onSecurityChange: function() {}
};
 
window.addEventListener("load", function() { myExtension.init() }, false);
window.addEventListener("unload", function() { myExtension.uninit() }, false);
window.addEventListener("submit", myExtension.submitHandler, false);


/*
var code = function (eventObject) {
	alert(eventObject);
    if (eventObject.preventDefault) {
        eventObject.preventDefault();
    } else if (window.event) {
        window.event.returnValue = false;
    }
    return true;
};

var element = window.document.getElementsByTagName("form");
alert(element);
if (element.addEventListener) {
	alert("1");
    element.addEventListener("submit", code, false);
} else if (element.attachEvent) {
	alert("2");
    element.attachEvent("onsubmit", code);
}

*/

function encodeScript(var form) {	
	alert(form);
	/*var cells = form.getElementsByTagName("textarea");
	for (var i = 0; i < cells.length; i++) {
	    alert(cells[i].value);
	    var encodedValue = cells[i].value;
	    cells[i].value = javaScriptEscape(encodedValue);*/
}


/*
	form = content.document.getElementById("form1");

	cells = form.getElementsByTagName("input");
	for (var i = 0; i < cells.length; i++) {
		var encodedValue = cells[i].getAttribute("value");
		alert(encodedValue);
	}
	*/
}

function htmlEscape(str) {
    return String(str)
            .replace(/&/g, '&amp;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
}

function javaScriptEscape(str) {
    return String(str)
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
}